<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:p="http://primefaces.org/ui"
	xmlns:form="http://java.sun.com/jsf/composite/components/form"
	xmlns:sec="http://www.springframework.org/security/tags"
	template="/templates/include/securedmain.xhtml">

	<ui:define name="content">
		<h:form id="form">
			<p:growl id="growl" showDetail="true" sticky="false" />
			<p:dataTable var="usr" value="#{userTableBean.objectDataModel}"
				paginator="true" rows="10"
				filteredValue="#{userTableBean.filteredObjects}"
				selection="#{userTableBean.selectedObjects}" id="objectsTable">

				<!-- This is a workaround for proper multiselection (guys from prime are loosers) -->
				<p:ajax event="toggleSelect" update="@this" process="@this" />
				<p:ajax event="rowSelectCheckbox" update="@this" />
				<p:ajax event="rowUnselectCheckbox" update="@this" />
				<p:ajax event="rowSelect" update="@this" />
				<p:ajax event="rowUnselect" update="@this" />

				<p:column selectionMode="multiple" style="width:2%" />

				<f:facet name="header">
					#{msg['menu.users']}
				</f:facet>

				<p:column headerText="#{msg['properties.user.firstname']}"
					id="usrFirst" filterBy="#{usr.firstName}">
					<h:outputText value="#{usr.firstName}" />
				</p:column>

				<p:column headerText="#{msg['properties.user.surname']}"
					id="usrLast" filterBy="#{usr.surname}">
					<h:outputText value="#{usr.surname}" />
				</p:column>

				<p:column headerText="#{msg['properties.user.nickname']}"
					id="usrNick" filterBy="#{usr.nickname}">
					<h:outputText value="#{usr.nickname}" />
				</p:column>

				<p:column headerText="#{msg['properties.user.role']}" id="usrRole">
					<h:outputText value="#{usr.role}" />
				</p:column>


				<p:column headerText="#{msg['view.actions']}" id="editAcs">
					<p:button id="viewButton" outcome="view/viewuser"
						title="#{msg['view.actions.view']}" icon="ui-icon-search"
						update="@form" ajax="false">
						<f:param name="id" value="#{usr.id}" />
					</p:button>

					<p:button id="calendarButton" outcome="usercalendar"
						title="#{msg['view.actions.calendar']}" icon="ui-icon-calendar"
						update="@form" ajax="false">
						<f:param name="id" value="#{usr.id}" />
					</p:button>
					<p:button id="icalButton" 
					
						title="#{msg['view.actions.calendar.ical']}" icon="ui-icon-link"
						update="@form" ajax="false"
						onclick="window.open('../userical.ics?id=#{usr.id}'); return false;"
						>
						<f:param name="id" value="#{usr.id}" />
					</p:button>	
					<sec:authorize ifAnyGranted="ROLE_ADMIN">
						<p:button id="changePassButton"
							outcome="/admin/edit/edituserchangepass"
							title="#{msg['view.actions.changepass']}" icon="ui-icon-unlocked"
							update="@form" ajax="false">
							<f:param name="id" value="#{usr.id}" />
						</p:button>
						<p:button id="editButton" outcome="/admin/edit/edituser"
							title="#{msg['view.actions.edit']}" icon="ui-icon-pencil"
							update="@form" ajax="false">
							<f:param name="id" value="#{usr.id}" />
						</p:button>
					</sec:authorize>
				</p:column>


				<f:facet name="footer">
					<sec:authorize ifAnyGranted="ROLE_ADMIN">
						<p:commandButton id="showDialogButton"
							value="#{msg['view.actions.delete']}" icon="ui-icon-trash"
							onclick="confirmation.show()" type="button" />
						<p:button id="createObjectButton"
							value="#{msg['view.actions.create']}" icon="ui-icon-circle-plus"
							outcome="/admin/edit/createuser" />
					</sec:authorize>
				</f:facet>
			</p:dataTable>
		</h:form>
		<p:confirmDialog id="confirmDialog" appendToBody="true"
			message="#{msg['view.actions.delete.label']}"
			header="#{msg['view.actions.delete']}" severity="alert"
			widgetVar="confirmation">

			<!-- update="messages" -->
			<p:commandButton id="confirm"
				value="#{msg['view.actions.button.commit']}"
				oncomplete="confirmation.hide()"
				actionListener="#{userTableBean.deleteSelectedObjects}"
				update="form" />
			<p:commandButton id="decline"
				value="#{msg['view.actions.button.cancel']}"
				onclick="confirmation.hide()" type="button" />
		</p:confirmDialog>

	</ui:define>
</ui:composition>
